package com.ruoyi.questionnaire.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.questionnaire.domain.QuestionnaireOption;
import com.ruoyi.questionnaire.service.IQuestionnaireOptionService;

@RestController
@RequestMapping("/questionnaire/option")
public class QuestionnaireOptionController extends BaseController {
    @Autowired
    private IQuestionnaireOptionService optionService;

    // 查询选项列表
    @GetMapping("/list")
    public TableDataInfo list(@RequestParam Long questionId) {
        List<QuestionnaireOption> list = optionService.selectQuestionnaireOptionList(questionId);
        return getDataTable(list);
    }

    // 查询选项详情
    @GetMapping("/{id}")
    public AjaxResult get(@PathVariable Long id) {
        return success(optionService.selectQuestionnaireOptionById(id));
    }

    // 新增选项
    @PostMapping
    public AjaxResult add(@RequestBody QuestionnaireOption option) {
        return toAjax(optionService.insertQuestionnaireOption(option));
    }

    // 修改选项
    @PutMapping("/{id}")
    public AjaxResult edit(@PathVariable Long id, @RequestBody QuestionnaireOption option) {
        option.setId(id);
        return toAjax(optionService.updateQuestionnaireOption(option));
    }

    // 删除选项
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id) {
        return toAjax(optionService.deleteQuestionnaireOptionById(id));
    }

    // 批量删除某题目下所有选项
    @DeleteMapping("/byQuestion/{questionId}")
    public AjaxResult removeByQuestion(@PathVariable Long questionId) {
        return toAjax(optionService.deleteQuestionnaireOptionByQuestionId(questionId));
    }
} 